package com.hfdg.coordination.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfdg.prototype.base.utils.TimeUtils;
import com.hfdg.coordination.mapper.CoordAttachmentMapper;
import com.hfdg.coordination.entity.CoordAttachment;
import com.hfdg.coordination.service.CoordAttachmentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * @ClassName CoordAttachmentServiceImpl
 * @Description CoordAttachment,主要对CoordAttachment类型数据的业务服务操作实现类
 * @Company 会飞的锅工作室
 * @Author yuelh
 * @Email 18695867679@163.com
 * @Date 2020/05/18 07:02:29
 * @Version 1.0
 **/
@Service
public class CoordAttachmentServiceImpl implements CoordAttachmentService {
    @Autowired
    CoordAttachmentMapper coordAttachmentMapper;
    @Override
    public String insert(CoordAttachment coordAttachment) {
        String uid = UUID.randomUUID().toString();
        coordAttachment.setUid(uid);
        coordAttachment.setDelFlag("0");
        coordAttachment.setCreateTime(new Date());
        coordAttachmentMapper.insert(coordAttachment);
        return uid;
    }

    @Override
    public Integer update(CoordAttachment coordAttachment) {
        coordAttachment.setUpdateTime(new Date());
        return coordAttachmentMapper.update(coordAttachment);
    }

    @Override
    public Integer  delete(String uid) {
        return coordAttachmentMapper.delete(uid);
    }
    @Override
    public Integer batchDelete(String[] uids) {
            return coordAttachmentMapper.batchDelete(uids);
    }

    @Override
    public CoordAttachment get(String uid) {
        return coordAttachmentMapper.get(uid);
    }

    @Override
    public List<CoordAttachment> list(CoordAttachment coordAttachment) {
    return  coordAttachmentMapper.list(coordAttachment);
    }

    @Override
    public PageInfo<CoordAttachment> getPagingData(int offset, int limit,String orderBy, CoordAttachment coordAttachment) {
        if(null==orderBy|| StringUtils.isBlank(orderBy)){
        PageHelper.startPage((offset/limit)+1,limit);
        }else{
        PageHelper.startPage((offset/limit)+1,limit,orderBy);
        }
        PageInfo<CoordAttachment> pageInfo =new PageInfo<>(coordAttachmentMapper.list(coordAttachment));
            return pageInfo;
            }
    @Override
    public String insertOrUpdate(CoordAttachment coordAttachment){
        if(null!=coordAttachment.getUid()){
            this.update(coordAttachment);
        }else{
            this.insert(coordAttachment);
        }
        return coordAttachment.getUid();
    }
            }
